package com.wuyan.locationdog.view

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import com.arcsoft.commonbase.R
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SPUtils
import com.wuyan.locationdog.databinding.DialogMapSetBinding


class MapSetDialog(
    context: Context,
    var sureCallback: () -> Unit
) :
    Dialog(context, R.style.CommonDialog) {

    var mapStyle = "style1"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//使用ViewBinding的写法
        val mBinding = DialogMapSetBinding.inflate(getLayoutInflater());
        val mView = mBinding.getRoot();

        setContentView(mView);

        window?.apply {
            attributes.dimAmount = 0.3f
            addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
        }
        mBinding.apply {
            btnHead.setOnClickListener {
                btnHead.setShapeStrokeColor(ColorUtils.getColor(R.color.text_color_selected))
                    .setShapeSolidColor(ColorUtils.getColor(R.color.text_color_selected_5))
                    .setShapeStrokeWidth(2)
                    .setUseShape()
                btnOther.setShapeStrokeColor(ColorUtils.getColor(R.color.common_stroke_color))
                    .setShapeSolidColor(Color.WHITE)
                    .setShapeStrokeWidth(1)
                    .setUseShape()
                btnHeadText.setTextColor(ColorUtils.getColor(R.color.text_color_selected))
                btnOtherText.setTextColor(ColorUtils.getColor(R.color.text_color_unselected))
                mapStyle = "style1"

            }
            btnOther.setOnClickListener {
                btnHead.setShapeStrokeColor(ColorUtils.getColor(R.color.common_stroke_color))
                    .setShapeSolidColor(Color.WHITE)
                    .setShapeStrokeWidth(1)
                    .setUseShape()
                btnOther.setShapeStrokeColor(ColorUtils.getColor(R.color.text_color_selected))
                    .setShapeSolidColor(ColorUtils.getColor(R.color.text_color_selected_5))
                    .setShapeStrokeWidth(2)
                    .setUseShape()

                btnHeadText.setTextColor(ColorUtils.getColor(R.color.text_color_unselected))
                btnOtherText.setTextColor(ColorUtils.getColor(R.color.text_color_selected))
                mapStyle = "style2"

            }
            if (SPUtils.getInstance().getString("mapStyle") == "style2") {
                btnOther.callOnClick()
            }
        }
        findViewById<View>(R.id.btn_sure).setOnClickListener {
            SPUtils.getInstance().put("mapStyle", mapStyle)
            dismiss()
            sureCallback.invoke()
        }
        findViewById<View>(R.id.btnCancel).setOnClickListener {
            dismiss()
        }
    }


}



